﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Repositories;
using Enterprise.Framework.Core.Exceptions;

namespace Resto.CostControl.Core.Domain.Query.DishModule
{
    internal class DishDQO : IDomainQueryObject
    {
        public Dish GetDish(string id)
        {
            Dish material = GetDishOrDefault(id);

            if (material == null)
                throw new BusinessException("指定Id的菜肴不存在");

            return material;
        }

        public Dish GetDishOrDefault(string id)
        {
            IEntityRepository<Dish> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Dish>();
            Dish material = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return material;
        }

    }
}
